/**
 * @file 032.有效的变位词.cc
 * @author snow-tyan (zziywang@163.com)
 * @brief {Life is too short to learn cpp.}
 * @version 0.1
 * @date 2021-12-11
 *
 * @copyright Copyright (c) 2021
 *
 */

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution
{
public:
    bool isAnagram(string s, string t)
    {
        if (s.size() != t.size() || s == t) {
            return false;
        }
        vector<int> cnt(26, 0);
        for (int i = 0; i < s.size(); ++i) {
            ++cnt[s[i] - 'a'];
        }
        for (int i = 0; i < t.size(); ++i) {
            --cnt[t[i] - 'a'];
            if (cnt[t[i] - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }
};

int main()
{
    cout << Solution().isAnagram("anagram", "nagaram") << endl;
    cout << Solution().isAnagram("rat", "car") << endl;
    cout << Solution().isAnagram("a", "a") << endl;
    return 0;
}
